package com.rp.system.user.util;

import com.rp.common.config.redis.RedisUtil;
import com.rp.common.config.shiro.ShiroRealm;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

/**
 * 类说明:清理缓存
 *
 * @author ****
 * @date 2021-03-29 16:27  新建
 */
@Service
public class ClearRedis {

    
    DefaultWebSecurityManager securityManager = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager();
    ShiroRealm shiroRealm = (ShiroRealm) securityManager.getRealms().iterator().next();

    /**
     * @Author HuJingYu
     * @Date 16:54 2021-03-29
     * @Description  清除所有授权缓存
     * @return void
     */
    public void clearAllCachedAuthorizationInfo(){
        shiroRealm.clearAllCachedAuthorizationInfo();
        System.out.println("清除所有授权缓存");
    }

    /**
     * @Author HuJingYu
     * @Date 16:54 2021-03-29
     * @Description  清除所有认证缓存
     * @return void
     */
    public void clearAllCachedAuthenticationInfo(){
        shiroRealm.clearAllCachedAuthorizationInfo();
        System.out.println("清除所有认证缓存");
    }

    /**
     * @Author HuJingYu
     * @Date 16:54 2021-03-29
     * @Description  清除所有认证 授权缓存
     * @return void
     */
    public void clearAllCache(){
        shiroRealm.clearAllCache();
        System.out.println("清除所有认证 授权缓存");
    }
    
}
